// 7进制数
// https://leetcode.cn/problems/base-7/description/

/**
 * 给定一个整数 num，将其转化为 7 进制，并以字符串形式输出。

 

示例 1:

输入: num = 100
输出: "202"
示例 2:

输入: num = -7
输出: "-10"
 */

/**
 * @param {number} num
 * @return {string}
 */
var convertToBase7 = function (num) {
    let ret = '';
    let isNeg = num < 0;

    let absNum = Math.abs(num);

    while (absNum >= 7) {
        let remain = absNum % 7;
        absNum = Math.floor(absNum / 7);

        ret = remain + ret;
    }

    ret = absNum + ret;

    if (isNeg) {
        ret = '-' + ret;
    }

    return ret;
};

console.log(convertToBase7(100) === '202');
console.log(convertToBase7(-7) === '-10');
